#!/bin/bash
# This file a part of SHM. Copyright (C) Tom Li 2013.
# License: LGPL version 3 or later.


USERNAME=$1
DOMAIN=$2

args=("$@")
for ((i=2; i<$#; i++))
do
    arg=${args[$i]}
    DOMAINS="${DOMAINS} ${arg}"
done

read -r -d '' CONF << EOF
server {
    server_name ${DOMAIN} www.${DOMAIN}${DOMAINS};

    listen 106.187.38.29;
    root /home/${USERNAME}/web;
    index index.html index.htm index.php;
    access_log /var/log/virtualhost/${DOMAIN}_access_log;
    error_log /var/log/virtualhost/${DOMAIN}_error_log;

    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;

    #include /etc/nginx/wordpress.conf;

    location ~ \.php$ {
        try_files \$uri =404;
        fastcgi_pass unix:/var/run/virtualhost/php-${DOMAIN}.sock;
    }
}
EOF

echo "$CONF"
